package testPaperWrong.jsonWrong;

import android.util.Log;

import com.example.hyznbk.presenter.presenter_interface.IBaseReviewPresenter;
import com.example.hyznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import java.util.List;

import lancooUpLoad.DataPackage;
import lancooUpLoad.PaperInfor;
import testPaperWrong.WrongQuesPaperActivity;

/**
 * Created by Administrator on 2017/8/29/029.
 */

public class WrongQuesPresenter implements IBaseReviewPresenter {

    private ILoadPaperView view;

    public WrongQuesPresenter(ILoadPaperView view) {
        this.view =  view;
    }

    @Override
    public void getData(boolean isShowLoading) {
          if (isShowLoading) view.showLoading();
        HttpOnNextListener<List<WrongQuesJson>> httpOnNextListener = new HttpOnNextListener<List<WrongQuesJson>>() {

            @Override
            public void onNext(List<WrongQuesJson> basicReviewWrongJson) {
                int totalCount = basicReviewWrongJson.size();
                Log.e("====totalCount====","==="+totalCount);
                if(totalCount>0){
                    view.hideLoading();
                    view.loadData(basicReviewWrongJson);
                }else {
                    view.showNoData("错题获取异常...");
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        };
        WrongQuesParam api = new WrongQuesParam(httpOnNextListener, (WrongQuesPaperActivity)view);

        Log.e("====getData====","===PaperFrom==="+UserInfo.PaperFrom);

        api.setGetQuesParams(DataPackage.getQuesParams(UserInfo.StuId,UserInfo.SubjectId,UserInfo.StageNo,UserInfo.PaperFrom,
                PaperInfor.QuesID));
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

}